//
//  Auth.m
//  ChampoinPeso
//
//  Created by mac on 2025/2/16.
//

#import "Auth.h"
#import "Info.h"
#import "Face.h"
#import "SDCycleScrollView.h"
#import "StepIndicatorView.h"
#import "Bank.h"
#import "Standing.h"
#import "Contact.h"
#import "Work.h"
#import "DataFrameWeb.h"
#import "LocationUpdata.h"
#import <SDWebImage/SDWebImage.h>
@interface Auth ()<SDCycleScrollViewDelegate>
@property(nonatomic,strong)UIScrollView *scrollView;
@property (nonatomic,strong)UIView *scrollContentView;
@property(nonatomic,strong)UILabel *mLabel;
@property (nonatomic,strong)UILabel *rateLabel;
@property (nonatomic,strong)UILabel *termLabel;
@property (nonatomic,strong)UILabel *rate;
@property (nonatomic,strong)UILabel *term;
@property (nonatomic,strong)UILabel *dw;
@property (nonatomic,strong)UIButton *apply;
@property (nonatomic,strong)UIButton *agree;
@property (nonatomic,strong)UIButton *agreetext;
@property (nonatomic,strong)NSMutableDictionary *source;
@property (nonatomic,strong)NSMutableArray *items;
@property (nonatomic,strong)NSMutableDictionary *nowItem;
@property (nonatomic,strong)NSMutableDictionary *agreeItem;
@property (nonatomic,strong)UIView *authStepView;
@property (nonatomic, strong)SDCycleScrollView *step;
@property (nonatomic, strong) UIPageControl *pageControl;
@property (nonatomic, strong) StepIndicatorView *stepIndicatorView;
@property (nonatomic,assign)NSInteger mIndex;
@property (nonatomic,strong)UILabel *alabel;
@property (nonatomic,strong)UIButton *stepButton;
@property (nonatomic,strong)UIImageView *icon;
@property (nonatomic,strong)NSMutableArray *titles;
@end

@implementation Auth

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    UIImageView *bgIV = [[UIImageView alloc] initWithFrame:self.view.bounds];
    bgIV.image = [UIImage imageNamed:@"auth_bg"];
    [self.view addSubview:bgIV];

    self.navtitleText = @"Product Detail";
    UIScrollView *scroll = [[UIScrollView alloc]initWithFrame:CGRectZero];
    [self.view addSubview:scroll];
    [scroll mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.mas_offset(0);
        make.top.mas_offset(64+MarginTop);
    }];
    [self navUI];
    self.navView.backgroundColor = UIColor.clearColor;
    _scrollView = scroll;
    scroll.userInteractionEnabled = YES;
    [_scrollView addSubview:self.scrollContentView];
    [self.scrollContentView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(_scrollView);
        make.width.mas_equalTo(SCREEN_WIDTH);
    }];
    UIView *view = [UIView new];
    [_scrollContentView addSubview:view];
    _scrollContentView.userInteractionEnabled = YES;
    [view mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_offset(13);
        make.left.mas_offset(13);
        make.right.mas_offset(-13);
        make.height.mas_equalTo(172);
    }];
    view.backgroundColor = UIColor.clearColor;
    UIImageView *img = [UIImageView new];
    img.image =[UIImage imageNamed:@"auth_top"];
    img.contentMode = UIViewContentModeScaleToFill;
    [view addSubview:img];
    [img mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.bottom.mas_offset(0);
    }];
    UIImageView *icon = [UIImageView new];
//    icon.image = [UIImage imageNamed:@"aicon"];
    [view addSubview:icon];
    icon.layer.cornerRadius = 10;
    icon.layer.masksToBounds = YES;
    [icon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_offset(-15);
        make.top.mas_offset(-13);
        make.size.mas_equalTo(CGSizeMake(60, 60));
    }];
    _icon = icon;
    UILabel *label = [UILabel new];
    label.text = @"₱";
    label.textColor = HexColor(@"#000000");
    label.font = [UIFont systemFontOfSize:42 weight:UIFontWeightBold];
    [view addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_offset(43);
        make.left.mas_offset(18);
    }];
    _dw = label;
    [view addSubview:self.mLabel];
    [_mLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(label.mas_right).offset(2);
        make.bottom.mas_equalTo(label);
    }];
    UIView *tipsView = [UIView new];
    [view addSubview:tipsView];
    [tipsView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_offset(-22);
        make.left.mas_offset(18);
        make.right.mas_offset(-18);
        make.height.mas_equalTo(54);
    }];
    UIImageView *tipsbg = [UIImageView new];
    tipsbg.image =  [UIImage imageNamed:@"auth_top_bg"];
    tipsbg.contentMode = UIViewContentModeScaleToFill;
    [tipsView addSubview:tipsbg];
    [tipsbg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.bottom.mas_offset(0);
    }];
    UILabel *rate = [UILabel new];
    rate.text = @"Interest rate";
    rate.font = [UIFont systemFontOfSize:10];
    rate.textColor = MainColor;
    [tipsView addSubview:rate];
    [rate mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_offset(11);
        make.left.mas_offset(70);
    }];
    _rate = rate;
    [tipsView addSubview:self.rateLabel];
    [_rateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(rate.mas_bottom).offset(2);
        make.centerX.mas_equalTo(rate);
    }];
    
    UILabel *term = [UILabel new];
    term.text = @"Minimum term";
    term.font = [UIFont systemFontOfSize:10];
    term.textColor = MainColor;
    [tipsView addSubview:term];
    [term mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_offset(11);
        make.right.mas_offset(-70);
    }];
    _term = term;
    [tipsView addSubview:self.termLabel];
    [_termLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(term.mas_bottom).offset(2);
        make.centerX.mas_equalTo(term);
    }];
    UIView *mid = [UIView new];
    [_scrollContentView addSubview:mid];
    [mid mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(view.mas_bottom).offset(17);
        make.left.mas_offset(12);
        make.right.mas_offset(-12);
        make.height.mas_equalTo(395);
        make.bottom.mas_offset(-120);
    }];
    UIImageView *bgg = [UIImageView new];
    bgg.userInteractionEnabled  = YES;
    bgg.image = [UIImage imageNamed:@"auth_mid"];
    bgg.contentMode = UIViewContentModeScaleToFill;
    [mid addSubview:bgg];
    [bgg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.bottom.mas_offset(0);
    }];
    [mid addSubview:self.authStepView];
    [_authStepView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_offset(70);
        make.left.right.bottom.mas_offset(0);
    }];
    [self.view addSubview:self.apply];
    [_apply mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_offset(-bottomSafeHeight-35);
        make.left.mas_offset(24);
        make.right.mas_offset(-24);
        make.height.mas_equalTo(52);
    }];
    [self.view addSubview:self.agree];
    _agree.selected = YES;
    [_agree mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(28);
        make.bottom.equalTo(_apply.mas_top).offset(-12);
    }];
    UILabel *alabel = [UILabel new];
    alabel.text = @"I’ve confirm and agree to the ";
    alabel.textColor = DetailColor;
    alabel.font = [UIFont systemFontOfSize:13];
    [self.view addSubview:alabel];
    self.alabel = alabel;
    [alabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_agree.mas_right).offset(4);
        make.centerY.mas_equalTo(_agree);
    }];
    //    <Loan agreement>
    [self.view addSubview:self.agreetext];
    [_agreetext mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(alabel.mas_right).offset(4);
        make.centerY.mas_equalTo(alabel);
    }];
    [_agree addTarget:self action:@selector(agreec:) forControlEvents:UIControlEventTouchUpInside];
    [_agreetext addTarget:self action:@selector(agreetextc) forControlEvents:UIControlEventTouchUpInside];
    [_apply addTarget:self action:@selector(gotoApply) forControlEvents:UIControlEventTouchUpInside];
}
-(void)agreec:(UIButton *)sender{
    sender.selected = !sender.selected;
}
-(NSMutableArray *)titles
{
    if (!_titles) {
        _titles = [NSMutableArray array];
    }
    return _titles;
}
-(void)agreetextc{
    NSString *str = self.agreeItem[@"aroused"];
    DataFrameWeb *web = [DataFrameWeb new];
    web.frameTo = str ;
    [self.navigationController pushViewController:web animated:YES];
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [self authSource];
}

-(void)gotoApply
{
    NSString *next = self.nowItem[@"clearthat"];
    if ([next isEqualToString:@""]) {
        if (!_agree.selected) {
            [self showAutoMessage:@"Please read and agree to the agreement first" ToView:self.view];
            return;
        }
        NSDictionary *params = @{@"zinc":self.source[@"insolence"],@"doubts":[NSString stringWithFormat:@"%@",self.source[@"doubts"]],@"almost":self.source[@"almost"],@"whistles":self.source[@"whistles"]};
        [DataFrameMove frameMoverForPost:@"/cham/tale" MoverPost:YES frameParm:params finish:^(id  _Nonnull info) {
            if ([info[@"gardening"] integerValue] == 0) {
                self.items = [NSMutableArray arrayWithArray:info[@"fashion"][@"six"]];
                self.nowItem = [NSMutableDictionary dictionaryWithDictionary:info[@"fashion"][@"report"]];
                self.source = [NSMutableDictionary dictionaryWithDictionary:info[@"fashion"][@"beamed"]];
                self.agreeItem = [NSMutableDictionary dictionaryWithDictionary:info[@"fashion"][@"fiftyfiveher"]];
                [self startMark:@"9"];
                [self updateUI];
                DataFrameWeb *web = [DataFrameWeb new];
                web.frameTo = CPS(info[@"fashion"][@"stop"]);
                [self.navigationController pushViewController:web animated:YES];
            }
        }];
    }else{
        [self gotoNext];
    }
}

-(void)gotoApplyDetail
{
    NSDictionary *dict = self.items[_mIndex];
    NSInteger over = [dict[@"perfect"] integerValue];
    if (over == 1) {
        [self gotoIndex];
    }else{
        [self gotoNext];
    }
}

-(void)gotoNext{
    NSString *next = self.nowItem[@"clearthat"];
    if ([next isEqualToString:@"Ia"]) {
        Face *vc = [Face new];
        [self.navigationController pushViewController:vc animated:YES];
//        Work *vc = [Work new];
//        vc.pid = self.pid;
//        vc.name = self.nowItem[@"supposing"];
//        [self.navigationController pushViewController:vc animated:YES];

    }else if ([next isEqualToString:@"Ib"]) {
        Standing *vc = [Standing new];
        vc.pid = self.pid;
        vc.name = self.nowItem[@"supposing"];
        [self.navigationController pushViewController:vc animated:YES];
    }else if ([next isEqualToString:@"Ic"]) {
        Work *vc = [Work new];
        vc.pid = self.pid;
        vc.name = self.nowItem[@"supposing"];
        [self.navigationController pushViewController:vc animated:YES];
    }else if ([next isEqualToString:@"Id"]) {
        Contact *vc = [Contact new];
        vc.pid = self.pid;
        vc.name = self.nowItem[@"supposing"];
        [self.navigationController pushViewController:vc animated:YES];
    }else if ([next isEqualToString:@"Ie"]) {
        //url stop
        DataFrameWeb *web = [DataFrameWeb new];
        web.frameTo = self.nowItem[@"stop"];
        web.name = self.nowItem[@"supposing"];
        [self.navigationController pushViewController:web animated:YES];
    }
}

-(void)gotoIndex{
//    NSInteger index = _mIndex;
    NSDictionary *dict = self.items[_mIndex];
    NSString *next = dict[@"clearthat"];
    if ([next isEqualToString:@"Ia"])
    {
        Face *vc = [Face new];
        [self.navigationController pushViewController:vc animated:YES];
    }
    else if ([next isEqualToString:@"Ib"])
    {
        Standing *vc = [Standing new];
        vc.pid = self.pid;
        vc.name = dict[@"supposing"];
        [self.navigationController pushViewController:vc animated:YES];
    }
    else if ([next isEqualToString:@"Ic"])
    {
        Work *vc = [Work new];
        vc.pid = self.pid;
        vc.name = dict[@"supposing"];
        [self.navigationController pushViewController:vc animated:YES];
    }
    else if ([next isEqualToString:@"Id"])
    {
        Contact *vc = [Contact new];
        vc.pid = self.pid;
        vc.name = dict[@"supposing"];
        [self.navigationController pushViewController:vc animated:YES];
    }
    else if ([next isEqualToString:@"Ie"])
    {
        // url
        DataFrameWeb *web = [DataFrameWeb new];
        web.frameTo = dict[@"stop"];
        web.name = dict[@"supposing"];
        [self.navigationController pushViewController:web animated:YES];
    }
}

-(NSMutableDictionary *)source
{
    if (!_source) {
        _source =  [NSMutableDictionary dictionary];
    }
    return _source;
}

-(NSMutableArray *)items
{
    if (!_items) {
        _items = [NSMutableArray  array];
    }
    return _items;
}

-(NSMutableDictionary *)nowItem
{
    if (!_nowItem) {
        _nowItem = [NSMutableDictionary dictionary];
    }
    return _nowItem;
}

-(NSMutableDictionary *)agreeItem
{
    if (!_agreeItem) {
        _agreeItem = [NSMutableDictionary dictionary];
    }
    return _agreeItem;
}

-(UIView *)authStepView
{
    if (!_authStepView) {
        _authStepView = [UIView new];
        [_authStepView addSubview:self.step];
        [_step mas_makeConstraints:^(MASConstraintMaker *make) {
            make.size.mas_equalTo(CGSizeMake(220, 220));
            make.centerX.mas_equalTo(_authStepView);
            make.top.mas_offset(16);
        }];
        
//        _step.localizationImageNamesGroup = @[@"auth1",@"auth2",@"auth3",@"auth4",@"auth5"];
        [_authStepView addSubview:self.pageControl];
        [_authStepView sendSubviewToBack:self.pageControl];
        [_pageControl mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(_step.mas_bottom).offset(0);
            make.centerX.mas_equalTo(_authStepView);
            make.size.mas_equalTo(CGSizeMake(SCREEN_WIDTH, 30));
        }];
        
        
//        _stepButton.userInteractionEnabled =YES;
//        [_authStepView addSubview:self.stepButton];
//        [_stepButton mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.left.right.top.bottom.equalTo(_step);
//        }];
    }
    return _authStepView;
}

-(SDCycleScrollView *)step{
    if (!_step) {
        //hd_pic_banner
        _step = [SDCycleScrollView cycleScrollViewWithFrame:CGRectZero delegate:self placeholderImage:[UIImage imageNamed:@""]];
        
        UIView *titleContainer = [[UIView alloc] initWithFrame:CGRectZero];
        titleContainer.backgroundColor = [UIColor clearColor];
        UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        titleLabel.textColor = UIColor.blackColor;
        titleLabel.font = [UIFont systemFontOfSize:16 weight:UIFontWeightMedium];
        titleLabel.tag = 1001;
        
        [_step addSubview:titleContainer];
        [titleContainer mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.right.mas_offset(0);
            make.height.mas_equalTo(80);
        }];
        
        [titleContainer addSubview:titleLabel];
        [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.center.mas_equalTo(titleContainer);
        }];

        
        _step.backgroundColor = UIColor.clearColor;
        _step.pageControlStyle = SDCycleScrollViewPageContolStyleNone;
        _step.autoScrollTimeInterval = 3;
        _step.layer.cornerRadius = 16;
        _step.layer.masksToBounds = YES;
        _step.delegate = self;
        _step.userInteractionEnabled = YES;
        _step.clickItemOperationBlock = ^(NSInteger currentIndex) {
        };
    }
    return _step;
}

- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didScrollToIndex:(NSInteger)index
{
    _mIndex = index;
    self.pageControl.currentPage = index;
    if (self.titles.count>index) {
        UILabel *label = [cycleScrollView viewWithTag:1001];
        label.text = self.titles[index];
    }
}
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index{
    [self gotoApplyDetail];
}
-(UIPageControl *)pageControl
{
    if (!_pageControl) {
        _pageControl = [[UIPageControl alloc] initWithFrame:CGRectZero];
        _pageControl.numberOfPages = 5;
        _pageControl.currentPage = 0;
        _pageControl.pageIndicatorTintColor = HexColor(@"#EFEFEF");
        _pageControl.currentPageIndicatorTintColor = HexColor(@"#2C64FF");
        [_pageControl setTransform:CGAffineTransformMakeScale(1.5, 1.5)];
    }
    return _pageControl;
}

-(void)authSource{
    NSDictionary *params = @{@"gossip":_pid};
    [DataFrameMove frameMoverForPost:@"/cham/neck" MoverPost:YES frameParm:params finish:^(id  _Nonnull info) {
        [self->_icon sd_setImageWithURL:[NSURL URLWithString:info[@"fashion"][@"beamed"][@"sorrow"]] placeholderImage:[UIImage imageNamed:@"aicon"]];
        self.items = [NSMutableArray arrayWithArray:info[@"fashion"][@"six"]];
        [self.titles removeAllObjects];
        NSMutableArray *ts = [NSMutableArray array];
        [self.items enumerateObjectsUsingBlock:^(NSDictionary *  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            [self.titles addObject:obj[@"supposing"]];
            [ts addObject:@""];
        }];
        UILabel *label = [self->_step viewWithTag:1001];
        label.text = self.titles[0];

        self->_pageControl.numberOfPages = ts.count;
//        self.stepIndicatorView.titles = ts;
        if (!self->_stepIndicatorView) {
            self.stepIndicatorView = [[StepIndicatorView alloc] initWithFrame:CGRectZero Titles:ts];
            [self->_authStepView addSubview:self.stepIndicatorView];
            [self.stepIndicatorView mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.equalTo(self->_pageControl.mas_bottom).offset(15);
                make.left.mas_offset(35);
                make.right.mas_offset(-35);
                make.height.mas_equalTo(30);
            }];
        }
        self.nowItem = [NSMutableDictionary dictionaryWithDictionary:info[@"fashion"][@"report"]];
        self.source = [NSMutableDictionary dictionaryWithDictionary:info[@"fashion"][@"beamed"]];
        self.agreeItem = [NSMutableDictionary dictionaryWithDictionary:info[@"fashion"][@"fiftyfiveher"]];
        [self->_apply setTitle:info[@"fashion"][@"beamed"][@"deckwhat"] forState:UIControlStateNormal];
        NSString *title = info[@"fashion"][@"beamed"][@"continued"];
        if (![CPS(title) isEqualToString:@""]) {
            self.namess = title;
        }
        NSString *adjadjadj = [NSString stringWithFormat:@"%@",info[@"fashion"][@"beamed"][@"adjadjadj"]];
        [[NSUserDefaults standardUserDefaults] setObject:adjadjadj forKey:@"adjadjadj"];
        NSString *ssOrd = info[@"fashion"][@"beamed"][@"insolence"];
        [[NSUserDefaults standardUserDefaults] setObject:ssOrd forKey:@"orderG"];
        [[NSUserDefaults standardUserDefaults] synchronize];
        [self updateUI];
    }];
}

-(void)updateUI {
    _mLabel.text = [NSString stringWithFormat:@"%@",self.source[@"doubts"]];
    _rate.text = self.source[@"flashed"][@"glimpse"][@"supposing"];
    _term.text = self.source[@"flashed"][@"lifesized"][@"supposing"];
    if ([CPS(self.source[@"flashed"][@"symbol"]) isEqualToString:@""]) {
        _dw.text =  @"₱";
    }else{
        _dw.text = CPS(self.source[@"flashed"][@"symbol"]);
    }
    _rateLabel.text = self.source[@"flashed"][@"glimpse"][@"certainly"];
    _termLabel.text = self.source[@"flashed"][@"lifesized"][@"certainly"];
    __block int step = 0;
    NSMutableArray *imgs = [NSMutableArray array];
    [self.items enumerateObjectsUsingBlock:^(NSDictionary*  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        NSInteger over = [obj[@"perfect"] integerValue];
        NSString *name = obj[@"clearthat"];
        NSInteger index = 1 ;
        if ([name isEqualToString:@"Ia"]) {
            index = 1;
        }else if ([name isEqualToString:@"Ib"]){
            index = 2;
        }else if ([name isEqualToString:@"Ic"]){
            index = 3;
        }else if ([name isEqualToString:@"Id"]){
            index = 4;
        }else if ([name isEqualToString:@"Ie"]){
            index = 5;
        }
        if (over == 0) {
            [imgs addObject:[NSString stringWithFormat:@"auth_step%lus",(unsigned long)index]];
        }else{
            [imgs addObject:[NSString stringWithFormat:@"auth_step%lu",(unsigned long)index]];
            step++;
        }
    }];
    self.step.localizationImageNamesGroup = imgs;
    if (![self.agreeItem[@"aroused"] isEqualToString:@""]) {
        NSString *str = self.agreeItem[@"supposing"];
        NSArray *items = [str componentsSeparatedByString:@"||"];
        self.alabel.text = items[0];
        [self.agreetext setTitle:[NSString stringWithFormat:@"<%@>",items[1]] forState:UIControlStateNormal];
    }else{
        self.alabel.hidden = YES;
        _agree.hidden = YES;
        _agreetext.hidden = YES;
    }
    [_stepIndicatorView setStepIndex:step-1];
}

-(UIView *)scrollContentView{
    if (!_scrollContentView) {
        _scrollContentView = [UIView new];
    }
    return _scrollContentView;
}

-(UILabel *)mLabel
{
    if (!_mLabel) {
        _mLabel = [UILabel new];
//        _mLabel.text = @"80,000";
        _mLabel.textColor = HexColor(@"#000000");
        _mLabel.font = [UIFont systemFontOfSize:48 weight:UIFontWeightBold];
    }
    return _mLabel;
}

-(UILabel *)rateLabel
{
    if (!_rateLabel) {
        _rateLabel = [UILabel new];
        _rateLabel.text = @"0.03%/day";
        _rateLabel.textColor = MainColor;
        _rateLabel.font = [UIFont systemFontOfSize:13];
    }
    return _rateLabel;
}
-(UILabel *)termLabel
{
    if (!_termLabel) {
        _termLabel = [UILabel new];
        _termLabel.text = @"300days";
        _termLabel.textColor = MainColor;
        _termLabel.font = [UIFont systemFontOfSize:13];
    }
    return _termLabel;
}

-(UIButton *)apply
{
    if (!_apply) {
        _apply = [UIButton buttonWithType:UIButtonTypeCustom];
        _apply.titleLabel.textColor = [UIColor whiteColor];
        _apply.titleLabel.font = [UIFont systemFontOfSize:18];
        [_apply setBackgroundImage:[UIImage imageNamed:@"auth_apply_bg"] forState:UIControlStateNormal];
    }
    return _apply;
}

-(UIButton *)agree
{
    if (!_agree) {
        _agree = [UIButton buttonWithType:UIButtonTypeCustom];
//        [_agree setBackgroundImage:[UIImage imageNamed:@"agree"] forState:UIControlStateNormal];
//        [_agree setBackgroundImage:[UIImage imageNamed:@"noagree"] forState:UIControlStateSelected];
        [_agree setImage:[UIImage imageNamed:@"auth_agree"] forState:UIControlStateNormal];
        [_agree setImage:[UIImage imageNamed:@"auth_agree_yes"] forState:UIControlStateSelected];
    }
    return _agree;
}

-(UIButton *)agreetext
{
    if (!_agreetext) {
        _agreetext = [UIButton buttonWithType:UIButtonTypeCustom];
        [_agreetext setTitle:@"<Loan agreement>" forState:UIControlStateNormal];
        [_agreetext setTitleColor:HexColor(@"#2C64FF") forState:UIControlStateNormal];
        _agreetext.titleLabel.font = [UIFont systemFontOfSize:13];
        [_agreetext addTarget:self action:@selector(agreeClick) forControlEvents:UIControlEventTouchUpInside];
    }
    return _agreetext;
}

-(void)agreeClick{
    NSString *url = self.agreeItem[@"aroused"];
}

-(UIButton *)stepButton
{
    if (!_stepButton) {
        _stepButton = [UIButton  buttonWithType:UIButtonTypeCustom];
        [_stepButton setBackgroundColor:[UIColor clearColor]];
        [_stepButton addTarget:self action:@selector(gotoApplyDetail) forControlEvents:UIControlEventTouchUpInside];
    }
    return _stepButton;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
